home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_LevelImage.c < prev    next >
C/C++ Source or Header  |  1995-09-29  |  11KB  |  480 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_LEVEL_KIND
  10. VOID __regargs
  11. LTP_DrawLevelImageLeft(struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,struct Image *Image,WORD Left,WORD Top,WORD Width,WORD Height,WORD OffsetX,WORD OffsetY)
  12. {
  13.     WORD    BorderTop    = Level -> KnobTop,
  14.             BorderLeft    = Level -> KnobWidth;
  15.  
  16.     Left    += OffsetX;
  17.     Top        += OffsetY;
  18.  
  19.     if(Width > 0)
  20.     {
  21.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  22.  
  23.         Move(RPort,Left,Top);
  24.         Draw(RPort,Left,Top + Height - 1);
  25.  
  26.         if(Width > 1)
  27.         {
  28.             Move(RPort,Left + 1,Top);
  29.             Draw(RPort,Left + 1,Top + Height - 2);
  30.  
  31.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  32.  
  33.             WritePixel(RPort,Left + 1,Top + Height - 1);
  34.  
  35.             if(Width > 2)
  36.             {
  37.                 Move(RPort,Left + 2,Top + Height - 1);
  38.                 Draw(RPort,Left + Width - 1,Top + Height - 1);
  39.  
  40.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  41.  
  42.                 Move(RPort,Left + 2,Top);
  43.                 Draw(RPort,Left + Width - 1,Top);
  44.  
  45.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[FILLPEN]);
  46.  
  47.                 RectFill(RPort,Left + 2,Top + 1,Left + Width - 1,Top + Height - 2);
  48.             }
  49.         }
  50.  
  51.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  52.  
  53.         RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top - 1);
  54.         RectFill(RPort,Left,Top + Height,Left + Width - 1,Top + Height + BorderTop - 1);
  55.         RectFill(RPort,Left - BorderLeft,Top - BorderTop,Left - 1,Top + Height + BorderTop - 1);
  56.     }
  57.     else
  58.     {
  59.         if(Level -> Position < BorderLeft)
  60.         {
  61.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  62.  
  63.             Left    = Image -> LeftEdge + OffsetX;
  64.             Width    = Level -> Position;
  65.  
  66.             if(Width > 0)
  67.                 RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top + Height + BorderTop - 1);
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73. /*****************************************************************************/
  74.  
  75.  
  76. VOID __regargs
  77. LTP_DrawLevelImageRight(struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,struct Image *Image,WORD Left,WORD Top,WORD Width,WORD Height,WORD OffsetX,WORD OffsetY)
  78. {
  79.     WORD    BorderTop    = Level -> KnobTop,
  80.             BorderLeft    = Level -> KnobWidth;
  81.  
  82.     Left    += OffsetX;
  83.     Top        += OffsetY;
  84.  
  85.     if(Width > 0)
  86.     {
  87.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  88.  
  89.         Move(RPort,Left + Width - 1,Top);
  90.         Draw(RPort,Left + Width - 1,Top + Height - 1);
  91.  
  92.         if(Width > 1)
  93.         {
  94.             Move(RPort,Left + Width - 2,Top + 1);
  95.             Draw(RPort,Left + Width - 2,Top + Height - 1);
  96.  
  97.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHADOWPEN]);
  98.  
  99.             WritePixel(RPort,Left + Width - 2,Top);
  100.  
  101.             if(Width > 2)
  102.             {
  103.                 Move(RPort,Left,Top);
  104.                 Draw(RPort,Left + Width - 3,Top);
  105.  
  106.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[SHINEPEN]);
  107.  
  108.                 Move(RPort,Left,Top + Height - 1);
  109.                 Draw(RPort,Left + Width - 3,Top + Height - 1);
  110.  
  111.                 LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  112.  
  113.                 RectFill(RPort,Left,Top + 1,Left + Width - 3,Top + Height - 2);
  114.             }
  115.         }
  116.  
  117.         LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  118.  
  119.         RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top - 1);
  120.         RectFill(RPort,Left,Top + Height,Left + Width - 1,Top + Height + BorderTop - 1);
  121.         RectFill(RPort,Left + Width,Top - BorderTop,Left + Width + BorderLeft - 1,Top + Height + BorderTop - 1);
  122.     }
  123.     else
  124.     {
  125.         Width = Image -> Width - (Level -> Position + 2 * BorderLeft);
  126.  
  127.         if(Width > 0)
  128.         {
  129.             LTP_SetAPen(RPort,DrawInfo -> dri_Pens[BACKGROUNDPEN]);
  130.  
  131.             Left = Image -> LeftEdge + OffsetX + 2 * BorderLeft + Level -> Position;
  132.  
  133.             if(Width > 0)
  134.                 RectFill(RPort,Left,Top - BorderTop,Left + Width - 1,Top + Height + BorderTop - 1);
  135.         }
  136.     }
  137. }
  138.  
  139.  
  140. /*****************************************************************************/
  141.  
  142.  
  143. VOID __regargs
  144. LTP_DrawLevelImageKnob(struct RastPort *RPort,struct DrawInfo *DrawInfo,WORD Left,WORD Top,WORD Width,WORD Height,LevelImageInfo *Level,BOOL Selected)
  145. {
  146.     UWORD    Shine    = DrawInfo -> dri_Pens[SHINEPEN],
  147.             Shadow    = DrawInfo -> dri_Pens[SHADOWPEN],
  148.             Fill    = Selected ? DrawInfo -> dri_Pens[FILLPEN] : DrawInfo -> dri_Pens[BACKGROUNDPEN],
  149.             Back    = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  150.  
  151.     Width = Level -> KnobWidth * 2;
  152.  
  153.     Left += Level -> Position - Level -> KnobWidth;
  154.  
  155.     if((Fill == Shine || Fill == Shadow) && Fill != Back)
  156.         Shine = Shadow = Back;
  157.  
  158.     LTP_SetAPen(RPort,Fill);
  159.  
  160.     RectFill(RPort,Left + 2,Top + 1,Left + 2 + Width - 3,Top + Height - 1);
  161.  
  162.     LTP_SetAPen(RPort,Shine);
  163.  
  164.     Move(RPort,Left + 1,Top + 1);
  165.     Draw(RPort,Left + 1,Top + Height - 2);
  166.     Draw(RPort,Left,Top + Height - 1);
  167.     Draw(RPort,Left,Top);
  168.     Draw(RPort,Left + Width - 2,Top);
  169.  
  170.     Move(RPort,Left + Width / 2,Top + 2);
  171.     Draw(RPort,Left + Width / 2,Top + Height - 3);
  172.  
  173.     LTP_SetAPen(RPort,Shadow);
  174.  
  175.     Move(RPort,Left + Width - 2,Top + Height - 2);
  176.     Draw(RPort,Left + Width - 2,Top + 1);
  177.     Draw(RPort,Left + Width - 1,Top);
  178.     Draw(RPort,Left + Width - 1,Top + Height - 1);
  179.     Draw(RPort,Left + 1,Top + Height - 1);
  180.  
  181.     Move(RPort,Left + Width / 2 - 1,Top + 2);
  182.     Draw(RPort,Left + Width / 2 - 1,Top + Height - 3);
  183. }
  184.  
  185.  
  186. /*****************************************************************************/
  187.  
  188.  
  189. VOID __regargs
  190. LTP_DrawLevelImageComplete(struct Image *Image,struct RastPort *RPort,struct DrawInfo *DrawInfo,LevelImageInfo *Level,WORD OffsetX,WORD OffsetY,BOOL Selected)
  191. {
  192.     WORD    BorderTop    = Level -> KnobTop,
  193.             BorderLeft    = Level -> KnobWidth,
  194.             Left,Top,
  195.             Width,Height;
  196.     LONG    Position;
  197.  
  198.     Left    = Image -> LeftEdge + BorderLeft;
  199.     Top        = Image -> TopEdge + BorderTop;
  200.     Width    = Image -> Width - 2 * BorderLeft;
  201.     Height    = Image -> Height - 2 * BorderTop;
  202.  
  203.     Position = Level -> Position + Left;
  204.  
  205.     SetAfPt(RPort,NULL,0);
  206.  
  207.     LTP_DrawLevelImageKnob(RPort,DrawInfo,Image -> LeftEdge + BorderLeft + OffsetX,Image -> TopEdge + OffsetY,Image -> Width - 2 * BorderLeft,Image -> Height,Level,Selected);
  208.     LTP_DrawLevelImageLeft(RPort,DrawInfo,Level,Image,Left,Top,Position - BorderLeft - Left,Height,OffsetX,OffsetY);
  209.     LTP_DrawLevelImageRight(RPort,DrawInfo,Level,Image,Position + BorderLeft,Top,Left + Width - (Position + BorderLeft),Height,OffsetX,OffsetY);
  210. }
  211.  
  212.  
  213. /*****************************************************************************/
  214.  
  215.  
  216. ULONG __regargs
  217. LTP_LevelClassDraw(struct Image *Image,struct impDraw *DrawMsg,LevelImageInfo *Level)
  218. {
  219.     struct RastPort *RPort = DrawMsg -> imp_RPort;
  220.  
  221.     if(RPort -> Layer)
  222.         LockLayerRom(RPort -> Layer);
  223.  
  224.     LTP_DrawLevelImageComplete(Image,RPort,Level -> DrawInfo,Level,DrawMsg -> imp_Offset . X,DrawMsg -> imp_Offset . Y,DrawMsg -> imp_State == IDS_SELECTED);
  225.  
  226.     if(DrawMsg -> imp_State == IDS_DISABLED)
  227.     {
  228.         WORD    Left    = Image -> LeftEdge    + DrawMsg -> imp_Offset . X,
  229.                 Top        = Image -> TopEdge    + DrawMsg -> imp_Offset . Y;
  230.  
  231. //        LTP_SetPens(RPort,Level -> DrawInfo -> dri_Pens[BLOCKPEN],0,JAM1);
  232.         LTP_SetPens(RPort,Level -> DrawInfo -> dri_Pens[BACKGROUNDPEN],0,JAM1);
  233.  
  234. //        SetAfPt(RPort,(UWORD *)&ghostingPat,1);
  235.         SetAfPt(RPort,(UWORD *)&checkPat,1);
  236.         RectFill(RPort,Left,Top,Left + Image -> Width - 1,Top + Image -> Height - 1);
  237.         SetAfPt(RPort,NULL,0);
  238.     }
  239.  
  240.     if(RPort -> Layer)
  241.         UnlockLayerRom(RPort -> Layer);
  242.  
  243.     return(TRUE);
  244. }
  245.  
  246.  
  247. /*****************************************************************************/
  248.  
  249.  
  250. ULONG __regargs
  251. LTP_LevelClassSet(Class *class,struct Image *Image,struct opSet *SetMsg)
  252. {
  253.     LevelImageInfo    *Level = (LevelImageInfo *)INST_DATA(class,Image);
  254.     struct TagItem    *Item,*List,*PositionItem = NULL;
  255.     LONG             Width = Image -> Width - 2 * Level -> KnobWidth;
  256.  
  257.     List = SetMsg -> ops_AttrList;
  258.  
  259.     while(Item = NextTagItem(&List))
  260.     {
  261.         switch(Item -> ti_Tag)
  262.         {
  263.             case LVIA_Current:
  264.  
  265.                 Level -> Current = Item -> ti_Data;
  266.                 break;
  267.  
  268.             case LVIA_Max:
  269.  
  270.                 Level -> Max = Item -> ti_Data;
  271.                 break;
  272.  
  273.             case LVIA_Position:
  274.  
  275.                 PositionItem = Item;
  276.                 break;
  277.         }
  278.     }
  279.  
  280.     if(PositionItem)
  281.     {
  282.         LONG Position = (LONG)PositionItem -> ti_Data;
  283.  
  284.         if(Position < 0 || !Level -> Max)
  285.             Position = 0;
  286.         else
  287.         {
  288.             if(Position > Width)
  289.                 Position = Width;
  290.         }
  291.  
  292.         Level -> Position = Position;
  293.     }
  294.     else
  295.     {
  296.         if(Level -> Max)
  297.             Level -> Position = (Width * Level -> Current) / Level -> Max;
  298.         else
  299.             Level -> Position = 0;
  300.     }
  301.  
  302.     return(DoSuperMethodA(class,(Object *)Image,SetMsg));
  303. }
  304.  
  305.  
  306. /*****************************************************************************/
  307.  
  308.  
  309. ULONG __regargs
  310. LTP_LevelClassGet(Class *class,struct Image *Image,struct opGet *GetMsg)
  311. {
  312.     LevelImageInfo *Level = (LevelImageInfo *)INST_DATA(class,Image);
  313.  
  314.     switch(GetMsg -> opg_AttrID)
  315.     {
  316.         case LVIA_Current:
  317.  
  318.             *GetMsg -> opg_Storage = Level -> Current;
  319.  
  320.             return(TRUE);
  321.  
  322.         case LVIA_Max:
  323.  
  324.             *GetMsg -> opg_Storage = Level -> Max;
  325.  
  326.             return(TRUE);
  327.  
  328.         case LVIA_Position:
  329.  
  330.             *GetMsg -> opg_Storage = Level -> Position;
  331.  
  332.             return(TRUE);
  333.  
  334.         case LVIA_KnobWidth:
  335.  
  336.             *GetMsg -> opg_Storage = Level -> KnobWidth;
  337.  
  338.             return(TRUE);
  339.  
  340.         case IA_SupportsDisable:
  341.  
  342.             *GetMsg -> opg_Storage = TRUE;
  343.  
  344.             return(TRUE);
  345.     }
  346.  
  347.     return(DoSuperMethodA(class,(Object *)Image,GetMsg));
  348. }
  349.  
  350.  
  351. /*****************************************************************************/
  352.  
  353.  
  354. ULONG __regargs
  355. LTP_LevelClassNew(Class *class,Object *object,struct opSet *SetMsg)
  356. {
  357.     LONG             Width        = 0,
  358.                      Height     = 0;
  359.     UWORD             FontWidth    = 0;
  360.     LONG             Current    = 0,
  361.                      Max        = 0;
  362.     struct DrawInfo *DrawInfo    = NULL;
  363.     struct TagItem    *List,
  364.                     *Item;
  365.  
  366.     List = SetMsg -> ops_AttrList;
  367.  
  368.     while(Item = NextTagItem(&List))
  369.     {
  370.         switch(Item -> ti_Tag)
  371.         {
  372.             case IA_Width:
  373.  
  374.                 Width = Item -> ti_Data;
  375.                 break;
  376.  
  377.             case IA_Height:
  378.  
  379.                 Height = Item -> ti_Data;
  380.                 break;
  381.  
  382.             case LVIA_FontWidth:
  383.  
  384.                 FontWidth = Item -> ti_Data;
  385.                 break;
  386.  
  387.             case LVIA_DrawInfo:
  388.  
  389.                 DrawInfo = (struct DrawInfo *)Item -> ti_Data;
  390.                 break;
  391.  
  392.             case LVIA_Current:
  393.  
  394.                 Current = (LONG)Item -> ti_Data;
  395.                 break;
  396.  
  397.             case LVIA_Max:
  398.  
  399.                 Max = (LONG)Item -> ti_Data;
  400.                 break;
  401.         }
  402.     }
  403.  
  404.     if(Width && Height >= 4 && DrawInfo)
  405.     {
  406.         struct Image *Image;
  407.  
  408.         if(Image = (struct Image *)DoSuperMethodA(class,object,(Msg)SetMsg))
  409.         {
  410.             LevelImageInfo    *Level = (LevelImageInfo *)INST_DATA(class,Image);
  411.             WORD             QuarterWidth,
  412.                              KnobWidth,
  413.                              LevelHeight;
  414.  
  415.             QuarterWidth    = (FontWidth + 3) / 4,
  416.             KnobWidth        = 3 * QuarterWidth,
  417.             LevelHeight        = (KnobWidth * DrawInfo -> dri_Resolution . X) / DrawInfo -> dri_Resolution . Y;
  418.  
  419.             if(LevelHeight >= Height)
  420.                 LevelHeight = Height / 4;
  421.  
  422.             if(LevelHeight < 4)
  423.             {
  424.                 if(Height > 4)
  425.                     LevelHeight = 4;
  426.                 else
  427.                     LevelHeight = Height;
  428.             }
  429.  
  430.             Level -> KnobWidth        = KnobWidth;
  431.             Level -> KnobTop        = (Height - LevelHeight) / 2;
  432.             Level -> LevelHeight    = LevelHeight;
  433.             Level -> Max            = Max;
  434.             Level -> Current        = Current;
  435.             Level -> DrawInfo        = DrawInfo;
  436.  
  437.             if(Max)
  438.                 Level -> Position = ((Width - 2 * KnobWidth) * Current) / Max;
  439.             else
  440.                 Level -> Position = 0;
  441.  
  442.             return((ULONG)Image);
  443.         }
  444.     }
  445.  
  446.     return(NULL);
  447. }
  448.  
  449.  
  450. /*****************************************************************************/
  451.  
  452.  
  453. ULONG __saveds __asm
  454. LTP_LevelClassDispatcher(register __a0 Class *class,register __a2 Object *object,register __a1 Msg msg)
  455. {
  456.     switch(msg -> MethodID)
  457.     {
  458.         case IM_DRAW:
  459.  
  460.             return(LTP_LevelClassDraw((struct Image *)object,(struct impDraw *)msg,(LevelImageInfo *)INST_DATA(class,object)));
  461.  
  462.         case OM_SET:
  463.  
  464.             return(LTP_LevelClassSet(class,(struct Image *)object,(struct opSet *)msg));
  465.  
  466.         case OM_GET:
  467.  
  468.             return(LTP_LevelClassGet(class,(struct Image *)object,(struct opGet *)msg));
  469.  
  470.         case OM_NEW:
  471.  
  472.             return(LTP_LevelClassNew(class,object,(struct opSet *)msg));
  473.  
  474.         default:
  475.  
  476.             return(DoSuperMethodA(class,object,msg));
  477.     }
  478. }
  479. #endif    /* DO_LEVEL_KIND */
  480.